<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>确认支付</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="payment-num">
    <div class="title">实付金额：</div>
    <div id="payNum" class="num"><i>￥</i>90.5</div>
</div>
<!-- 实付金额 -->

<div class="payment-method" id="paymentMethod">
    <div class="title bottom-border">选择支付方式</div>
    <!--<div class="method-item bottom-border on">-->
    <!--<img src="img/alipay.png" alt="" class="icon">-->
    <!--<div class="text">支付宝</div>-->
    <!--<div class="radio"></div>-->
    <!--</div>-->
    <div class="method-item bottom-border on">
        <img src="img/wechat.png" alt="" class="icon">
        <div class="text">微信支付</div>
        <div class="radio"></div>
    </div>
</div>
<!-- 支付方式 -->

<div class="button-section" onclick="payNow()">
    <!--<a href="success.html" class="button">确认支付</a>-->
     <a href="#" class="button">确认支付</a>
    <div class="zhanwei"></div>
</div>
<!-- 底部菜单 -->

<!-- 以下为页面js部分 -->
<script type="text/javascript" src="js/rem.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="application/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="js/pages/public.js" type="text/javascript" charset="utf-8"></script>
<script>
    $('#paymentMethod .method-item').click(function () {
        $(this).addClass('on').siblings().removeClass('on');
    })

    var orderId = getUrlParam('orderId');
    var totalFee = getUrlParam('totalFee');
    console.log(orderId);
    console.log(totalFee);
    $('#payNum').html('<i>￥</i>' + totalFee);

    // 选择支付方式
    function payNow() {
          wxPay(orderId,totalFee);
    }


    function wxPay(orderId, amount) {
        $.ajax({
            type: "post",
            url: ajaxUrl + "/mobile/order/wxPay",
            async: true,
            data: {'orderId': orderId, 'amount': amount},
            success: function (data) {
                console.log(data);

                if (data.code == 0) {
                    if (typeof WeixinJSBridge == "undefined") {
                 //       alert("1")
                        if (document.addEventListener) {
                            document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data.result), false);
                        } else if (document.attachEvent) {
                            document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data.result));
                            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data.result));
                        }
                    } else {
                        onBridgeReady(data.result);
                    }
                }
            }

        });
    }
    function onBridgeReady(data){
        console.log(data);
    //    alert(data.package_);
    WeixinJSBridge.invoke(
        'getBrandWCPayRequest',
        {
            "appId" : data.appId,     //公众号名称，由商户传入
            "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数
            "nonceStr" :data.nonceStr, //随机串
            //"package":"prepay_id="+data.prepayId,
           "package":data.package_,
            "signType" : data.signType,         //微信签名方式：
            "paySign" : data.paySign //微信签名
        },
        function(res){
           // alert(res)

          //  alert(JSON.stringify(res));
       //     alert("prepayId="+data.prepayId);
            if(res.err_msg == "get_brand_wcpay_request:ok" ) {
				window.location.href = '/success.html';
            }
        }
    );
}

</script>
</body>
</html>